﻿using System;
using System.Collections.Generic;

namespace SharpDepend.Classes.Threading
{
    public class CallQueueThreadSafe
    {
        private Queue<Action> mQueue = new Queue<Action>();

        public void QueueCall(Action call)
        {
            lock (this)
            {
                mQueue.Enqueue(call);
            }
        }

        public void CallAll()
        {
            lock (this)
            {
                while (mQueue.Count > 0)
                {
                    mQueue.Dequeue()();
                }
            }
        }

        public void Clear()
        {
            mQueue.Clear();
        }
    }

    public class CallQueue
    {
        private Queue<Action> mQueue = new Queue<Action>();

        public void QueueCall(Action call)
        {
            mQueue.Enqueue(call);
        }

        public void CallAll()
        {
            while (mQueue.Count > 0)
            {
                mQueue.Dequeue()();
            }
        }

        public void Clear()
        {
            mQueue.Clear();
        }
    }
}
